package com.weibo.survey.controller;

import javax.annotation.Resource;

import org.apache.struts2.interceptor.validation.SkipValidation;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.weibo.survey.domain.Page;
import com.weibo.survey.domain.Survey;
import com.weibo.survey.service.PageService;

@Controller("pageAction")
@Scope("prototype")
public class PageAction extends BaseAction<Page> {
	private static final long serialVersionUID = -2675311649694409427L;
	private static final String ADDPAGE = "addPage";
	private static final String DESIGNSERVEYACTION = "designSurveyAction";
	private static final String EDITPAGE = "editPage";

	private int sid;
	private int id;

	@Resource(name = "pageService")
	PageService pageService;

	@SkipValidation
	public String toAddPage() {
		model.setSurvey(new Survey(sid));
		return ADDPAGE;
	}

	// 添加页面
	public String addPage() {
		model.setSurvey(new Survey(sid));
		pageService.saveOrUpdateEnity(model);
		return DESIGNSERVEYACTION;
	}

	// 编辑页面
	public String editPage() {
		model = pageService.getPageWithChildren(model.getId());
		model.setSurvey(new Survey(sid));
		return EDITPAGE;
	}
	
	//删除页面
	public String deletePage(){
		pageService.deletePage(model.getId());
		return DESIGNSERVEYACTION;
	}
	

	public int getSid() {
		return sid;
	}

	public void setSid(int sid) {
		this.sid = sid;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}


}
